package com.silence.gmall.product.domain.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.repository.CrudRepository;
import com.silence.gmall.base.TableDataInfo;
import com.silence.gmall.product.assembler.SpuInfoFactory;
import com.silence.gmall.product.domain.entity.SpuInfo;
import com.silence.gmall.product.domain.mapper.SpuInfoMapper;
import com.silence.gmall.product.domain.repository.SpuInfoRepository;
import com.silence.gmall.product.dto.SpuInfoDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

/**
 * @Author silence
 * @Description 针对表【spu_info(商品表)】的数据库操作Repository实现
 * @Date 2025-08-17 16:28:16
 */
@Slf4j
@Repository
@RequiredArgsConstructor
public class SpuInfoRepositoryImpl extends CrudRepository<SpuInfoMapper, SpuInfo>
    implements SpuInfoRepository {

    /**
     * 商品工厂
     */
    private final SpuInfoFactory spuInfoFactory;

    /**
     * 获取spu分页列表
     *
     * @param page 当前页码
     * @param limit 当前页数
     * @param category3Id 三级分类ID
     * @return spu分页列表
     */
    @Override
    public TableDataInfo<SpuInfoDto> pageSpuInfo(Long page, Long limit, String category3Id) {
        return spuInfoFactory.pageSpuInfo2TableSpuInfoDto(page(new Page<>(page, limit),
                new LambdaQueryWrapper<SpuInfo>().eq(SpuInfo::getCategory3Id, category3Id)));
    }
} 